package com.jewelry.vo;

public class PageVO implements java.io.Serializable {

	private static final long serialVersionUID = -4041958872737037662L;

	//初始化需要设置的三个值
	public PageVO() {
		this.pageSize = 10;
		this.currentPage = 1;
		this.totalItem = 0;
	}
	
	/**
	 * 开始点
	 */
	private int start = 0;

	// 设置开始的记录数
	public void setStart(int start) {
		this.start = start;
	}

	public int getStart() {
		if (currentPage > 0) {
			start = (currentPage - 1) * pageSize;
		} else {
			start = 0;
		}
		return start;
	}

	/** 当前页 */
	private int currentPage = 1;

	public int getCurrentPage() {
		if (currentPage < 1) {
			currentPage = 1;
		}
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		if (currentPage < 1)
			currentPage = 1;
		else
			this.currentPage = currentPage;
	}

	// ===============================================

	/**
	 * 每页数量
	 */
	private int pageSize = 10;

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	// ===============================================

	/**
	 * 总条数
	 */
	private int totalItem = 0;

	public void setTotalItem(int totalItem) {
		this.totalItem = totalItem;
	}

	public int getTotalItem() {
		return totalItem;
	}

	// ==========================================

	/**
	 * 总页数
	 */
	private int totalPage;

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getTotalPage() {
		// 默认为10
		if (0 == pageSize) {
			pageSize = 10;
		}
		totalPage = (totalItem % pageSize == 0 ? (totalItem / pageSize)
				: totalItem / pageSize + 1);
		if (currentPage > totalPage) {
			currentPage = totalPage;
		}
		return totalPage;
	}
	
	public int getNextPage(){
		int nextPage = 2;
		if(currentPage<totalPage){
			nextPage = currentPage + 1;
		}else{
			nextPage = totalPage;
		}
		return nextPage;
	}
	
	public int getPrePage(){
		int prePage = 1;
		if(currentPage>1){
			prePage = currentPage - 1;
		}
		return prePage;
	}
	
}
